package edu.hawaii.duedates.web.page;

import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import edu.hawaii.duedates.web.page.alerts.Alerts;
import edu.hawaii.duedates.web.page.display.Display;
import edu.hawaii.duedates.web.page.index.Index;

/**
 * A Base page that serves as the superclass for all pages in this application.
 * All pages inherit from this class, including stylesheets.
 *  
 * @author Ronn Reeves
 */
public abstract class BasePage extends WebPage {
  /** Support serialization. */
  private static final long serialVersionUID = 1L;
  
  /**
   * The base page layout used by all pages. 
   * This includes a title and the links that appear in the tabbed menu. 
   */
  public BasePage() {
    setStyles();

    // Set page title.
    add(new Label("PageTitle", "DueDates-Omaomao"));
  }

  /**
   * Sets the master style.
   */
  private void setStyles() {
    // Add inherited stylesheets
    String path = "style/master/";
    String style = "master";
    String ext = ".css";
    add(HeaderContributor.forCss(
      edu.hawaii.duedates.web.page.BasePage.class, path + style + ext, "all"));
  }

  /** Login text. */
  protected final Label loginText = new Label("LoginText", "Login");

  /** Logout text. */
  protected final Label logoutText = new Label("LoginText", "Logout");
  
  /** Login link. */
  protected final Link loginLink = new Link("LoginLink") {
    private static final long serialVersionUID = 1L;

    /** Redirects to the Index page for logging in. */
    @Override
    public void onClick() {
      setResponsePage(new Index());
    }
  };

  /** Logout link. */
  protected final Link logoutLink = new Link("LoginLink") {
    private static final long serialVersionUID = 1L;

    /** 
     * Event handler for uxLogoutLink.onClick() event.
     * Log this user out of the application. 
     */
    @Override
   public void onClick() {
      getSession().invalidate();
      setResponsePage(Index.class);
    }
  };
  
  // Display link.
  protected final Link displayLink = new Link("DisplayLink") {
    private static final long serialVersionUID = 1L;

    /** Redirects to the Display page for querying of libraries. */
    @Override
    public void onClick() {
      setResponsePage(new Display());
    } 
  };

  // Alerts link.
  protected final Link alertsLink = new Link("AlertsLink") {
    private static final long serialVersionUID = 1L;

    /** Redirects to the Alerts page for email options. */
    @Override
    public void onClick() {
      setResponsePage(new Alerts());
    }
  };
}